<template>
	<div class="add-arrange-order">
		<div>
			<label>{{$t('route.Scheduling_management')}}</label>
			<div></div>
			<button><img /><label>{{this.form.id?$t('route.modify') : $t('route.Add')}}{{$t('route.Scheduling_plan')}}</label></button>
		</div>
		<div>
			<el-form size="medium" style="width: 30%;" label-width="120px">
				<el-form-item :label="$t('route.Customer')">
					<el-input v-model="form.customer" />
				</el-form-item>
				<el-form-item :label="$t('route.order_number')">
					<el-input v-model="form.orderCode" />
				</el-form-item>
				<el-form-item :label="$t('route.Payment_Number')">
					<el-select v-model="form.styleCode" filterable>
						<el-option v-for="item in styleCodeList" :key="item" :label="item" :value="item" />
					</el-select>
				</el-form-item>
				<el-form-item :label="$t('route.date_of_delivery')">
					<el-date-picker v-model="form.deliveryDate" type="date" :placeholder="$t('route.Select_date')" />
				</el-form-item>
				<el-form-item :label="$t('route.Payment_date')">
					<el-date-picker v-model="form.paymentDate" type="date" :placeholder="$t('route.Select_date')" />
				</el-form-item>
				<el-form-item :label="$t('route.Order_quantity')">
					<el-input-number v-model="form.orderNum" :min="1" />
				</el-form-item>
				<el-form-item :label="$t('route.Target_output')">
					<el-input-number v-model="form.targetNum" :min="1" />
				</el-form-item>
				<el-form-item :label="$t('route.production_team')">
					<el-select v-model="form.proLine" filterable>
						<el-option v-for="item in proLineNameList" :key="item" :label="item" :value="item" />
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button @click='addClick' type="primary">{{ this.form.id?$t('route.preservation') : $t('route.Add')}}</el-button>
				</el-form-item>
			</el-form>
		</div>


	</div>
</template>

<script>
	import http from "../../js/http/http.js";
	import api from "../../js/http/api.js";
	import CommonUtils from "../../js/common/common-utils.js";
	import i18n from '../../i18n/index';
	export default {
		data() {
			return {
				form: {
					customer: null,
					orderCode: null,
					styleCode: null,
					deliveryDate: new Date(),
					paymentDate: new Date(),
					orderNum: 1,
					targetNum: 1,
					proLine: null,
					stdDur: 1,
				},
				styleCodeList: [],
				proLineNameList: []

			};
		},
		methods: {
			getAllStyleCode() {
				http.post(api.GET_ALL_STYLE_CODE, {
					adminId: this.$store.state.user.id,
				}, data => {
					this.styleCodeList = data.data;
				})
			},
			getAllProLineName() {
				http.post(api.GET_ALL_PRO_LINE_NAME, {
					adminId: this.$store.state.user.id,
				}, data => {
					this.proLineNameList = data.data;
				})
			},
			addClick() {
				if (CommonUtils.isEmpty(this.form.customer)) {
					this.$message.error(i18n.global.t('route.Customer_cannot_be_empty'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.orderCode)) {
					this.$message.error(i18n.global.t('route.Order'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.styleCode)) {
					this.$message.error(i18n.global.t('route.Item'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.proLine)) {
					this.$message.error(i18n.global.t('route.Production_group_cannot_be_empty'));
					return;
				}
				this.form.adminId = this.$store.state.user.id;
				http.post(api.ADD_ARRANGE_ORDER, {
					arrangeOrderId: this.form.id,
					adminId: this.$store.state.user.id,
					customer: this.form.customer,
					orderCode: this.form.orderCode,
					styleCode: this.form.styleCode,
					deliveryDate: this.form.deliveryDate.format('yyyy-MM-dd'),
					paymentDate: this.form.paymentDate.format('yyyy-MM-dd'),
					orderNum: this.form.orderNum,
					targetNum: this.form.targetNum,
					proLine: this.form.proLine,
				}, data => {
					var title = this.form.id ? i18n.global.t('route.Modified_successfully') :i18n.global.t('route.Successfully_added');
					this.$message.success(title);
					this.$router.go(-1);
				});
			}
		},
		created() {
			var arrangeOrder = CommonUtils.getParam(this, 'arrangeOrder', 'setArrangeOrder');
			if (arrangeOrder) {
				this.form = JSON.parse(arrangeOrder);
				this.form.deliveryDate = new Date(this.form.deliveryDate);
				this.form.paymentDate = new Date(this.form.paymentDate);
			}
			this.getAllStyleCode();
			this.getAllProLineName();
		}
	};
</script>
<style lang="scss" scoped>
	.add-arrange-order {
		color: #444444;
		font-size: 18px;
		padding-right: 20px;
		height: calc(100vh - 100px);
		// overflow: scroll;
		scrollbar-width: none;
		/* firefox */
		-ms-overflow-style: none;
		/* IE 10+ */
		overflow-x: hidden;
		overflow-y: auto;

		.avatar {
			width: 130px;
			height: 130px;
		}

		>div:nth-of-type(1) {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;

			>label:nth-of-type(1) {
				font-weight: 600;
			}

			>div:nth-of-type(1) {
				width: 1px;
				background-color: #cccccc;
				height: 15px;
				margin: 0px 20px;
			}

			>button:nth-of-type(1) {
				background-image: url(../../assets/img/customer-1.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				padding: 5px 10px;
				border: 0px;
				display: flex;
				color: #ffffff;
				flex-direction: row;
				align-items: center;
				font-weight: 800;

				>img {
					margin-right: 7px;
					width: 15px;
					height: 15px;
					content: url(../../assets/img/customer-2.png);
				}

			}
		}

		>div:nth-of-type(2) {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;

			.input {}

			.div-1 {
				display: flex;
				flex-direction: row;

				>label {
					margin-left: 10px;
					width: 200px;
				}
			}


		}





	}
</style>
